package com.hyt.it.ogt.ykcj.service.exam.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hyt.it.ogt.ykcj.common.utils.DateUtils;
import com.hyt.it.ogt.ykcj.domain.exam.ChangedExamInfo;
import com.hyt.it.ogt.ykcj.mapper.exam.ChangedExamInfoMapper;
import com.hyt.it.ogt.ykcj.service.exam.IChangedExamInfoService;

/**
 * 考试信息变更记录Service业务层处理
 *
 * @author admin
 * @date 2021-08-10
 */
@Service
public class ChangedExamInfoServiceImpl implements IChangedExamInfoService {

  @Autowired
  private ChangedExamInfoMapper changedExamInfoMapper;

  /**
   * 查询考试信息变更记录
   *
   * @param examId 考试信息变更记录ID
   * @return 考试信息变更记录
   */
  @Override
  public ChangedExamInfo selectChangedExamInfoById(String examId) {
    return changedExamInfoMapper.selectChangedExamInfoById(examId);
  }

  /**
   * 查询考试信息变更记录列表
   *
   * @param changedExamInfo 考试信息变更记录
   * @return 考试信息变更记录
   */
  @Override
  public List<ChangedExamInfo> selectChangedExamInfoList(ChangedExamInfo changedExamInfo) {
    return changedExamInfoMapper.selectChangedExamInfoList(changedExamInfo);
  }

  /**
   * 新增考试信息变更记录
   *
   * @param changedExamInfo 考试信息变更记录
   * @return 结果
   */
  @Override
  public int insertChangedExamInfo(ChangedExamInfo changedExamInfo) {
    changedExamInfo.setCreateTime(DateUtils.getNowDate());
    return changedExamInfoMapper.insertChangedExamInfo(changedExamInfo);
  }

  /**
   * 修改考试信息变更记录
   *
   * @param changedExamInfo 考试信息变更记录
   * @return 结果
   */
  @Override
  public int updateChangedExamInfo(ChangedExamInfo changedExamInfo) {
    changedExamInfo.setUpdateTime(DateUtils.getNowDate());
    return changedExamInfoMapper.updateChangedExamInfo(changedExamInfo);
  }

  /**
   * 批量删除考试信息变更记录
   *
   * @param examIds 需要删除的考试信息变更记录ID
   * @return 结果
   */
  @Override
  public int deleteChangedExamInfoByIds(String[] examIds) {
    return changedExamInfoMapper.deleteChangedExamInfoByIds(examIds);
  }

  /**
   * 删除考试信息变更记录信息
   *
   * @param examId 考试信息变更记录ID
   * @return 结果
   */
  @Override
  public int deleteChangedExamInfoById(String examId) {
    return changedExamInfoMapper.deleteChangedExamInfoById(examId);
  }

  @Override
  public void addChangedExamInfo(String examId) {
    ChangedExamInfo changedExamInfo = changedExamInfoMapper.selectChangedExamInfoById(examId);
    if (null != changedExamInfo){
      changedExamInfo.setUpdateTime(DateUtils.getNowDate());
      changedExamInfoMapper.updateChangedExamInfo(changedExamInfo);
    }else {
      changedExamInfo = new ChangedExamInfo();
      changedExamInfo.setExamId(examId);
      changedExamInfo.setCreateTime(DateUtils.getNowDate());
      changedExamInfo.setUpdateTime(DateUtils.getNowDate());
      changedExamInfoMapper.insertChangedExamInfo(changedExamInfo);
    }
  }
}
